﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Manageweb/MemberMaster.master" AutoEventWireup="true" CodeFile="BuyCoffee.aspx.cs" Inherits="Manageweb_Coffee_BuyCoffee" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <title>购买咖啡机</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
 <style type="text/css">
        *
        {
            margin: 0;
        }
        body
        {
            font-size: 9pt;
        }
        #container div
        {
            margin-top: 6px;
        }
        #select_city h3
        {
            float: left;
        }
        #main_city, #all_province
        {
            clear: both;
        }
        #main_city div, #all_province div
        {
            width: 588px;
            clear: left;
        }
        #main_city h4, #all_province h4
        {
            float: left;
            display: inline;
            font-size: 16px;
        }
        #main_city div span, #all_province div span
        {
            margin: 0 9px;
            cursor: pointer;
            font-size: 14px;
        }
        #float_lay
        {
            width: 220px;
            height: 122px;
            border: 1px #787878 solid;
            position: absolute;
            background: #fff;
            z-index: 999;
            display: none;
        }
    </style>

    <script type="text/javascript">

        //弹出层
        function openLayer(objId, conId) {
            document.getElementById(conId).innerHTML = '请输入密钥：<input type="text" id="txt1" value="" /><br/><br/><input type="button" id="btnok" value="确定" onclick="Check();" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="btncannel" value="取消" onclick="quxiao();" />';

            var arrayPageSize = getPageSize(); //调用getPageSize()函数
            var arrayPageScroll = getPageScroll(); //调用getPageScroll()函数
            if (!document.getElementById("popupAddr")) {
                //创建弹出内容层
                var popupDiv = document.createElement("div");
                //给这个元素设置属性与样式
                popupDiv.setAttribute("id", "popupAddr")
                popupDiv.style.position = "absolute";
                popupDiv.style.border = "1px solid #ccc";
                popupDiv.style.background = "#fff";
                popupDiv.style.zIndex = 99;
                //创建弹出背景层
                var bodyBack = document.createElement("div");
                bodyBack.setAttribute("id", "bodybg")
                bodyBack.style.position = "absolute";
                bodyBack.style.width = "100%";
                bodyBack.style.height = (arrayPageSize[1] + 35 + 'px');
                bodyBack.style.zIndex = 98;
                bodyBack.style.top = 0;
                bodyBack.style.left = 0;
                bodyBack.style.filter = "alpha(opacity=50)";
                bodyBack.style.opacity = 0.5;
                bodyBack.style.background = "#ddf";
                //实现弹出(插入到目标元素之后)
                var mybody = document.getElementById(objId);
                insertAfter(popupDiv, mybody); //执行函数insertAfter()
                insertAfter(bodyBack, mybody); //执行函数insertAfter()
            }
            //显示背景层
            document.getElementById("bodybg").style.display = "";
            //显示内容层
            var popObj = document.getElementById("popupAddr")
            popObj.innerHTML = document.getElementById(conId).innerHTML;
            popObj.style.display = "";
            //让弹出层在页面中垂直左右居中(统一)
            // popObj.style.width  = "600px";
            // popObj.style.height = "400px";
            // popObj.style.top  = arrayPageScroll[1] + (arrayPageSize[3] - 35 - 400) / 2 + 'px';
            // popObj.style.left = (arrayPageSize[0] - 20 - 600) / 2 + 'px';
            //让弹出层在页面中垂直左右居中(个性)
            var arrayConSize = getConSize(conId)
            popObj.style.top = arrayPageScroll[1] + (arrayPageSize[3] - arrayConSize[1]) / 2   + 'px';
            popObj.style.left = (arrayPageSize[0] - arrayConSize[0]) / 2   + 'px';
        }
        //获取内容层内容原始尺寸
        function getConSize(conId) {
            var conObj = document.getElementById(conId)
            conObj.style.position = "absolute";
            conObj.style.left = -1000 + "px";
            conObj.style.display = "";
            var arrayConSize = [conObj.offsetWidth, conObj.offsetHeight]
            conObj.style.display = "none";
            return arrayConSize;
        }
        function insertAfter(newElement, targetElement) {//插入
            var parent = targetElement.parentNode;
            if (parent.lastChild == targetElement) {
                parent.appendChild(newElement);
            }
            else {
                parent.insertBefore(newElement, targetElement.nextSibling);
            }
        }
        //获取滚动条的高度
        function getPageScroll() {
            var yScroll;
            if (self.pageYOffset) {
                yScroll = self.pageYOffset;
            } else if (document.documentElement && document.documentElement.scrollTop) {
                yScroll = document.documentElement.scrollTop;
            } else if (document.body) {
                yScroll = document.body.scrollTop;
            }
            arrayPageScroll = new Array('', yScroll)
            return arrayPageScroll;
        }
        //获取页面实际大小
        function getPageSize() {
            var xScroll, yScroll;
            if (window.innerHeight && window.scrollMaxY) {
                xScroll = document.body.scrollWidth;
                yScroll = window.innerHeight + window.scrollMaxY;
            } else if (document.body.scrollHeight > document.body.offsetHeight) {
                sScroll = document.body.scrollWidth;
                yScroll = document.body.scrollHeight;
            } else {
                xScroll = document.body.offsetWidth;
                yScroll = document.body.offsetHeight;
            }
            var windowWidth, windowHeight;
            if (self.innerHeight) {
                windowWidth = self.innerWidth;
                windowHeight = self.innerHeight;
            } else if (document.documentElement && document.documentElement.clientHeight) {
                windowWidth = document.documentElement.clientWidth;
                windowHeight = document.documentElement.clientHeight;
            } else if (document.body) {
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
            }
            var pageWidth, pageHeight
            if (yScroll < windowHeight) {
                pageHeight = windowHeight;
            } else {
                pageHeight = yScroll;
            }
            if (xScroll < windowWidth) {
                pageWidth = windowWidth;
            } else {
                pageWidth = xScroll;
            }
            arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
            return arrayPageSize;
        }
        //关闭弹出层
        function closeLayer() {
            document.getElementById("popupAddr").style.display = "none";
            document.getElementById("bodybg").style.display = "none";
            return false;
        }
        
        function Check() {
            //获取输入密钥
            var inputKey = document.getElementById("txt1").value;
            //获取服务器端的密钥
            var ServerKey = '<%=StrKey %>';
            if (inputKey == ServerKey) {

                document.getElementById('<%=hidMiYao.ClientID %>').value = '1';
                // location.href("ViewXiaXian.aspx?isPass=" + isPass);
                document.getElementsByTagName('form')[0].submit();
            }
        }

        function quxiao() {
            location.href("../../Welcome1.aspx");
        }

    </script>
    <table id="TABLE_Buy" runat="server" border="1" cellpadding="0" cellspacing="0"
            visible="false" width="750" style="margin: 0 auto">
            <tr>
                <td colspan="2" style="font-weight: bold; color: white; background-color: #507cd1;
                    text-align: left">
                    &nbsp;<asp:Label ID="LB_TableTitle" runat="server">购买咖啡机</asp:Label>
                </td>
            </tr>
            <tr>
                <td style="width: 150px">
                    &nbsp;咖啡机:
                </td>
                <td style="text-align: left">
                    <asp:TextBox ID="txtCoffeeName" runat="server" Width="240px" Height="18px" 
                        ReadOnly="True"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;&nbsp;&nbsp;&nbsp; 价格:
                </td>
                <td style="text-align: left">
                    <asp:TextBox ID="txtCoffeePrice" runat="server" Width="240px" onmouseover="this.select();"
                        ReadOnly="True"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;&nbsp;&nbsp; 数量:
                </td>
                <td style="text-align: left">
                    <asp:TextBox ID="txtCoffeeCount" runat="server" Width="240px"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtCoffeeCount"
                        Display="Dynamic" ErrorMessage="*" ValidationGroup="Btn_Submit"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtCoffeeCount"
                        Display="Dynamic" ErrorMessage="格式错误,必须为正整数" ValidationExpression="^[0-9]*[1-9][0-9]*$"
                        ValidationGroup="Btn_Submit"></asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="font-weight: bold; color: white; background-color: #507cd1">
                    <asp:Button ID="Btn_Submit" runat="server" Text="提交" ValidationGroup="Btn_Submit"
                        OnClick="Btn_Submit_Click" />&nbsp; <asp:Button ID="Btn_Cancel" runat="server" Text="取消" />
                </td>
            </tr>
        </table>
   <br />
        <div style="text-align: center; width: 750px;">
            <asp:Label ID="LB_ManageUser" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Red"></asp:Label></div>
<br />
<div  style="width:750px; text-align:right; padding-bottom:8px"><a runat="server" href="ViewBuyCoffeeRecords.aspx">查看购买记录</a></div>
<table border="1" cellpadding="0" cellspacing="0" width="750px" style="margin: 0 auto">
            <tr>
                <td>
                    <asp:GridView ID="GV_CoffeeList" runat="server" AllowPaging="True" AllowSorting="True"
                        AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" Width="100%"
                        EmptyDataText="暂无数据" onpageindexchanging="GV_CoffeeList_PageIndexChanging" 
                        PageSize="15" >
                        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <RowStyle BackColor="#EFF3FB" />
                        <Columns>
                            <asp:BoundField DataField="name" HeaderText="咖啡机" />
                            <asp:BoundField DataField="price" HeaderText="单价" />
                            <asp:BoundField DataField="count" HeaderText="数量" />
                            <asp:BoundField DataField="createtime" HeaderText="日期" />
                            <asp:TemplateField HeaderText="操作">
                                <ItemTemplate>
                                    <asp:LinkButton ID="btnBuy" runat="server" CommandArgument='<%#String.Format("{0}|{1}|{2}|{3}",Eval("name"),Eval("count"),Eval("price"),Eval("ID")) %>' 
                                        OnCommand="btnBuy_Command">购买</asp:LinkButton>
                                 
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <EditRowStyle BackColor="#2461BF" />
                        <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>
                </td>
            </tr>
        </table>
    <asp:HiddenField ID="hidCoffeeID" runat="server" />
    <br />
    <asp:HiddenField ID="hidCoffeeCount" runat="server" />
      <asp:HiddenField ID="hidMiYao" runat="server" />
</asp:Content>

